package com.iflytek.xiri2.hal;

import com.iflytek.xiri.hal.IHAL;
import com.lz.abstractlist.HardwareINF;
import com.lz.abstractlist.HardwareIML;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

/**
 * 硬件抽象层
 * 
 * @author admin
 * 
 */
public class HAL implements IHAL {
	public static final String TAG = "HAL";
	private final String QueryDeviceInfoACTION = "com.iflytek.xiri2.hal.QueryDeviceInfo";
	private final String SetMuteACTION = "com.iflytek.xiri2.hal.SetMute";
	private final String GetVolumeACTION = "com.iflytek.xiri2.hal.GetVolume";
	private final String SetVolumeACTION = "com.iflytek.xiri2.hal.SetVolume";
	private final String GetBrightnessACTION = "com.iflytek.xiri2.hal.GetBrightness";
	private final String SetBrightnessACTION = "com.iflytek.xiri2.hal.SetBrightness";
	private final String IncreaseBrightnessACTION = "com.iflytek.xiri2.hal.IncreaseBrightness";
	private final String DecreaseBrightnessACTION = "com.iflytek.xiri2.hal.DecreaseBrightness";
	private final String GetSignalSourceListACTION = "com.iflytek.xiri2.hal.GetSignalSourceList";
	private final String SetSignalSourceACTION = "com.iflytek.xiri2.hal.SetSignalSource";
	private final String PowerOffACTION = "com.iflytek.xiri2.hal.PowerOff";
	private final String SendKeyACTION = "com.iflytek.xiri2.hal.SendKey";
	private final String SystemSettingACTION = "com.iflytek.xiri2.hal.SystemSetting";
	private final String NetworkSettingACTION = "com.iflytek.xiri2.hal.NetworkSetting";
	private final String ImageSettingACTION = "com.iflytek.xiri2.hal.ImageSetting";
	private final String SoundSettingACTION = "com.iflytek.xiri2.hal.SoundSetting";
	private final String NavigateACTION = "com.iflytek.xiri2.hal.Navigate";
	// 硬件抽象层实现类
	public static HardwareINF hardwareINF;
	// 录音时静音和取消静音的支持
	private final String RECMUTEACTION = "com.iflytek.xiri2.SetMute";
	/**
	 * 当前的静音状态
	 */
	public static boolean CURRENTMUTE = true;
	/**
	 * 是否语点静音
	 */
	public static boolean XIRIMUTE = false;
	/**
	 * 是否支持录音定制
	 */
	public static boolean ISSPORTMUTE = true;

	@Override
	public boolean control(Context context, String action, Bundle bundle) {
		if (null == hardwareINF) {
			hardwareINF = new HardwareIML(context);
		}
		Log.d(TAG, "action " + action + " " + bundle.toString());
		if (QueryDeviceInfoACTION.equals(action)) {
			bundle.putString("model", "TV");
			String id = hardwareINF.getDeviceId(context);
			if (null != id) {
				bundle.putString("deviceid", id);
			}
			bundle.putInt("minvolume", hardwareINF.getMinVolume(context));
			bundle.putInt("maxvolume", hardwareINF.getMaxVolume(context));
			bundle.putInt("volumestep", hardwareINF.getVoluemStep());
			// bundle.putInt("minbrightness", 0);
			// bundle.putInt("maxbrightness", 100);
			// bundle.putInt("brightnessstep", 5);
			Log.d(TAG, "halinfo" + bundle.toString());
			return true;
		} else if (SetMuteACTION.equals(action)) {
			boolean isMute = bundle.getBoolean("mute");
			Log.e(TAG, "SetMuteACTION" + isMute);
			hardwareINF.setMuteACTION(context, isMute);
			return true;
		} else if (GetVolumeACTION.equals(action)) {
			Log.e(TAG, "GetVolumeACTION" + hardwareINF.getCurVolume(context));
			// 获取当前系统音量
			bundle.putInt("volume", hardwareINF.getCurVolume(context));
			return true;
		} else if (SetVolumeACTION.equals(action)) {
			int volume = bundle.getInt("volume");
			Log.e(TAG, "SetVolumeACTION xiri set:" + volume);
			hardwareINF.setVolume(context, volume);
			// 设置音量
			return true;
		} else if (GetBrightnessACTION.equals(action)) {
			Log.e(TAG, "GetBrightnessACTION");
			return false;
		} else if (SetBrightnessACTION.equals(action)) {
			Log.e(TAG, "SetBrightnessACTION");
			return false;
		} else if (IncreaseBrightnessACTION.equals(action)) {
			Log.e(TAG, "IncreaseBrightnessACTION");
			return false;
		} else if (DecreaseBrightnessACTION.equals(action)) {
			Log.e(TAG, "DecreaseBrightnessACTION");
			return false;
		} else if (GetSignalSourceListACTION.equals(action)) {
			Log.e(TAG, "GetSignalSourceListACTION");
			return false;
		} else if (SetSignalSourceACTION.equals(action)) {
			Log.e(TAG, "SetSignalSourceACTION");
			return false;
		} else if (PowerOffACTION.equals(action)) {
			Log.e(TAG, "PowerOffACTION==========");
			// 关机
			return true;
		} else if (SendKeyACTION.equals(action)) {
			Log.e(TAG, "PowerOffACTION");
			// 发送虚拟按键
			return false;
		} else if (SystemSettingACTION.equals(action)) {
			Log.e(TAG, "SystemSettingACTION");
			// 系统设置
			return false;
		} else if (NetworkSettingACTION.equals(action)) {
			Log.e(TAG, "NetworkSettingACTION");
			// 网络设置
			return false;
		} else if (ImageSettingACTION.equals(action)) {
			Log.e(TAG, "ImageSettingACTION");
			// 图像设置
			return false;
		} else if (SoundSettingACTION.equals(action)) {
			Log.e(TAG, "SoundSettingACTION");
			return false;
		} else if (NavigateACTION.equals(action)) {
			return false;// hardwareINF.navigateACTION(context, url);
		} else if (RECMUTEACTION.equals(action)) {
			Log.e(TAG, "RECMUTEACTION" + bundle.getBoolean("mute"));
			// // 录音时静音的支持
			// boolean isMute = bundle.getBoolean("mute");
			// if (!isMute) {
			// Intent intent = new Intent("com.liefeng.xunfeiyuyin.ledControl");
			// intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
			// context.sendBroadcast(intent);
			// Log.e(TAG, "com.liefeng.xunfeiyuyin.ledControl");
			// }
			// Log.e(TAG, "return false");
			return false;
		}
		return false;
	}
}
